<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Api\BaseinitController;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
class TeacherController extends BaseinitController
{
	public function teachers(Request $request)
	{
        $pageNum=$request->input('page');
        $limit=10;
        $page=$pageNum-1;
        if ($page != 0) {
            $page = $limit * $page;
        }
        $teacher = DB::table('teacher')
            ->where('state',1)
            ->orderBy('recommend','asc')
            ->orderBy('uptime','desc')
            ->orderBy('id','desc')
            ->offset($page)
            ->take($limit)
            ->get();
        $data = [
            'code' => 0,
            'msg'   => '正在请求中...',
            'data'  => $teacher
        ];
        return response()->json($data);
	}
	public function teacherSearch(Request $request)
	{
        $pageNum=$request->input('page');
        $key=$request->input('key');
        $limit=12;
        $page=$pageNum-1;
        if ($page != 0) {
            $page = $limit * $page;
        }
        $teacher =DB::table('teacher')
            ->whereRaw("concat(`teacher`) like '%".$key."%'")
            ->where('state',1)
            ->orderBy('recommend','asc')
            ->orderBy('uptime','desc')
            ->orderBy('id','desc')
            ->offset($page)
            ->take($limit)
            ->get();
        $data = [
            'code' => 0,
            'msg'   => '正在请求中...',
            'data'  => $teacher
        ];
        return response()->json($data);
	}
    public function teacherIntro(Request $request)
    {
        $id=$request->input('id');
        $teacher =DB::table('teacher')->where('id',$id)->first();
        $course =DB::table('course')->where('t_id',$id)->where('state',1)->orderBy('recommend','asc')->orderBy('uptime','desc')->orderBy('id','desc')->get();
        $data = [
            'code' => 0,
            'msg'   => '正在请求中...',
            'intro'  => $teacher,
            'data'  => $course
        ];
        return response()->json($data);
    }
}